package com.AndroidApp.codememo;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class ChangePswd extends Activity {
	
	EditText oldpswd;
	EditText newpswd;
	Intent intent = new Intent(); 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.changepassword);
		oldpswd = (EditText) findViewById(R.id.old_pswd);
		newpswd = (EditText) findViewById(R.id.new_pswd);
		
		}
	
	public void onClickConfirm(View v) {
        // Perform action on click
		SharedPreferences myMemos = this.getSharedPreferences("myMemos", MODE_WORLD_READABLE);
        String prefNames = myMemos.getString("MY_PASSWORD", "nothing");
        if(prefNames.equalsIgnoreCase(oldpswd.getText().toString()))
        {
            SharedPreferences myMemo = getSharedPreferences("myMemos", MODE_WORLD_READABLE);  
            SharedPreferences.Editor prefEditor = myMemo.edit();  
            prefEditor.putString("MY_PASSWORD", newpswd.getText().toString());  
            prefEditor.commit();  
            
            intent.setClass(this,CodeMemoAppActivity.class);
        	startActivity(intent);
        }
        else
        {
        	TextView tv= (TextView) findViewById(R.id.errormsg);
        	tv.setText("Your Password is wrong..");
        }	

		/*SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
        SharedPreferences.Editor prefsEditor = myPrefs.edit();
        prefsEditor.putString("MY_PASSWORD", oldpswd.getText().toString());
        prefsEditor.commit();*/

    }
}